package com.tedu.m3;

import com.rabbitmq.client.*;
import com.sun.glass.ui.DelayedCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/11/30
 */
public class Consumer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory c = new ConnectionFactory();
        c.setHost("192.168.126.129");
        c.setPort(5672);
        c.setUsername("admin");
        c.setPassword("admin");
        Channel channel = c.newConnection().createChannel();
        channel.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);
        String queue = channel.queueDeclare().getQueue();
        channel.queueBind(queue, "logs", "");
        DeliverCallback delayedCallback = new DeliverCallback() {
            @Override
            public void handle(String consumerTag, Delivery message) throws IOException {
                String msg = new String(message.getBody());
                System.out.println(msg);
            }

        };

        CancelCallback cancelCallback = new CancelCallback() {
            @Override
            public void handle(String consumerTag) throws IOException {

            }
        };

        channel.basicConsume(queue, true, delayedCallback, cancelCallback);


    }
}
